﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Config;
using CNVP.Framework;

namespace CNVP.JShop.Web.Admin
{
    public partial class SystemSet : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 126)) return;//判断页面权限
            if (!IsPostBack)
            {
                
                txtSiteName.Text = UIConfig.SiteName;
                txtLogo.Text = UIConfig.Logo;
                if (UIConfig.Logo != "")
                {
                    imgPic.Visible = true;
                    imgPic.ImageUrl = "../UploadFile/Logo/" + UIConfig.Logo;
                }
                
                txtSiteDomain.Text = UIConfig.SiteDomain;
                txtSiteICP.Text = UIConfig.SiteICP;
                txtMailInfo.Text = UIConfig.MailInfo;
                txtMailUserName.Text = UIConfig.MailUserName;
                txtMailUserPass.Text = UIConfig.MailUserPass;
                txtMailServer.Text = UIConfig.MailServer;
                txtUserFilter.Text = UIConfig.UserFilter;
                txtKeyWords.Text = UIConfig.KeyWords;
                txtDescribe.Text = UIConfig.Describe;
                cbReviewIsApproved.Checked =(!String.IsNullOrEmpty(UIConfig.ReviewIsApproved) &&  UIConfig.ReviewIsApproved=="1");
            }
        }

        protected void btUp_Click(object sender, EventArgs e)
        {
            string _SiteName = txtSiteName.Text.Trim();
            string _Logo = txtLogo.Text.Trim();
            string _SiteDomain = txtSiteDomain.Text.Trim();
            string _SiteICP = txtSiteICP.Text.Trim();
            string _MailInfo = txtMailInfo.Text.Trim();
            string _MailUserName = txtMailUserName.Text.Trim();
            string _MailUserPass = txtMailUserPass.Text.Trim();
            string _MailServer = txtMailServer.Text.Trim();
            string _UserFilter = txtUserFilter.Text.Trim();
            string _KeyWords = txtKeyWords.Text.Trim();
            string _Describe = txtDescribe.Text.Trim();
            String reviewIsApproved = cbReviewIsApproved.Checked ? "1" : "0";
            BaseConfig.SaveXmlConfig("SiteName", _SiteName);
            string newName = "";
            string root = Server.MapPath("../UploadFile/Logo/");
            if (this.fileUp.PostedFile.ContentLength != 0)
            {
                string fileName = fileUp.PostedFile.FileName;
                string imgType = fileName.Substring(fileName.LastIndexOf(".") + 1);
                if (imgType.ToLower() != "jpg" && imgType.ToLower() != "bmp" && imgType.ToLower() != "gif" && imgType.ToLower() != "jpeg" && imgType.ToLower() != "png")
                {
                    BasePage.MessageBoxGoHistory("上传的图片必须为.jpg或.bmp或.gif或.jpeg或.png！");
                    return;
                }
                newName = "Logo_" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + "." + imgType;
                fileUp.PostedFile.SaveAs(root + "\\" + newName);
                imgPic.ImageUrl = "../UploadFile/Logo/" + newName;
            }
            else
            {
                newName = _Logo;
            }

            
            BaseConfig.SaveXmlConfig("Logo", newName);
            BaseConfig.SaveXmlConfig("SiteDomain", _SiteDomain);
            BaseConfig.SaveXmlConfig("SiteICP", _SiteICP);
            BaseConfig.SaveXmlConfig("MailInfo", _MailInfo);
            BaseConfig.SaveXmlConfig("MailUserName", _MailUserName);
            BaseConfig.SaveXmlConfig("MailUserPass", _MailUserPass);
            BaseConfig.SaveXmlConfig("MailServer", _MailServer);
            BaseConfig.SaveXmlConfig("UserFilter", _UserFilter);
            BaseConfig.SaveXmlConfig("ReviewIsApproved", reviewIsApproved);

            BaseConfig.SaveXmlConfig("KeyWords", _KeyWords);
            BaseConfig.SaveXmlConfig("Describe", _Describe);
            UIConfig.RefurbishCatch();//刷新缓存
            LicenseConfig.RefurbishCatch();
            BasePage.MessageBox("修改成功！", "SystemSet.aspx");
        }
    }
}